package com.ibiaoke.boss.controller;

import com.ibiaoke.common.base.BaseController;
import com.ibiaoke.common.response.Res;
import com.ibiaoke.common.utils.AssertUtils;
import com.ibiaoke.customer.entity.Customer;
import com.ibiaoke.customer.entity.vo.CustomerVO;
import com.ibiaoke.customer.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class AppCustomerController extends BaseController{

    @Autowired
    private CustomerService customerService;

    /**
     * App获取用户个人信息
     * @return
     */
    @RequestMapping("/getCustomerInfo")
    @ResponseBody
    public Res getCustomerInfo(String token){
        Customer customer = getLoginUser();
        Customer customer1 = customerService.getCustomerInfo(customer.getCustomerId());
        AssertUtils.requireTrue(token !=null ||token == customer.getToken(),"账户异常");
        return Res.create()
                .addResponse("customerNickname",customer1.getCustomerNickname())
                .addResponse("customerMobile",customer1.getCustomerMobile())
                .addResponse("customerImg",customer1.getCustomerImg())
                .addResponse("customerSex",customer1.getCustomerSex());
    }

    @ResponseBody
    @RequestMapping("/updateCustomerInfo")
    public Res updateCustomerInfo(CustomerVO customerVO){
        Customer customer = getLoginUser();
        AssertUtils.notNull(customer, "请登录");
        AssertUtils.requireTrue(customerVO.getToken() != null || customerVO.getToken() == customer.getToken(), "账户异常");
        customerService.updateCustomerInfo(customer.getCustomerId(),customerVO);
        return Res.create();
    }
}
